var app = getApp()
Page({

    data: {

        databuy: '',
        datasell: '',
        currentTab: 0,
        currentTab: 0,
        data: '',
        mask: false,
        maskoverly: false,


        currentTab: 0,
        winHeight: 0,
        buyid: '',
        sellid: ''

    },
    close: function(e) {
        this.setData({
            maskbuy: false,
            maskoverly: false,
            masksell: false
        })
    },
    //弹窗
    maskbuy: function(e) {
        var id = e.target.dataset.id;
        this.setData({
            maskbuy: true,
            maskoverly: true,
            buyid: id
        })
    },
    masksell: function(e) {
        var id = e.target.dataset.id;
        this.setData({
            masksell: true,
            maskoverly: true,
            sellid: id
        })
    },
    // 取消委托卖
    cancelsell: function(e) {
        this.setData({
            masksell: true,
            maskoverly: true,
            // sellid: id
        })
        var that = this;
        wx.getStorage({
            key: 'user',
            success: function(res) {
                wx.request({
                    url: app.url.requestUrl + '/myentrust/cancelsell',
                    method: 'POST',
                    data: {
                        openid: res.data.openid,
                        token: res.data.token,
                        id: that.data.sellid

                    },
                    header: {
                        'content-type': 'application/json'
                    },
                    success: function(res) {
                        console.log(res.data)
                        if (res.data.code == 1) {
                            that.setData({
                                masksell: false,
                                maskoverly: false,
                            })
                            wx.showToast({
                                title: res.data.msg,
                                icon: '',
                                duration: 2000,
                                mask: true
                            })
                        } else {
                            wx.showToast({
                                title: res.data.msg,
                                icon: '../img/icon-prompt.png',
                                duration: 2000,
                                mask: true
                            })
                        }

                    }
                })
            }
        })


    },

    // 取消委托买
    cancelbuy: function(e) {
        var that = this;
        wx.getStorage({
            key: 'user',
            success: function(res) {
                wx.request({
                    url: app.url.requestUrl + '/myentrust/cancelbuy',
                    method: 'POST',
                    data: {
                        openid: res.data.openid,
                        token: res.data.token,
                        id: that.data.buyid
                    },
                    header: {
                        'content-type': 'application/json'
                    },
                    success: function(res) {
                        console.log(res.data)
                        if (res.data.code == 1) {
                            that.setData({
                                maskbuy: false,
                                maskoverly: false,
                            })
                            wx.showToast({
                                title: res.data.msg,
                                icon: '',
                                duration: 2000,
                                mask: true
                            })
                        } else {
                            wx.showToast({
                                title: res.data.msg,
                                icon: '../img/icon-prompt.png',
                                duration: 2000,
                                mask: true

                            })
                        }
                    }
                })
            }
        })
    },
    //判断当前滚动超过一屏时，设置tab标题滚动条。
    checkCor: function() {
        if (this.data.currentTab > 4) {
            this.setData({
                scrollLeft: 300
            })
        } else {
            this.setData({
                scrollLeft: 0
            })
        }
    },
    bindGetUserInfo() {
        this.login.hideModalBox()
    },


    /**

     * 生命周期函数--监听页面加载

     */

    onLoad: function(options) {
        var that = this;
        wx.getStorage({
            key: 'user',
            success: function(res) {
                //委托买
                wx.request({
                        url: app.url.requestUrl + '/myentrust/buy',
                        method: 'POST',
                        data: {
                            openid: res.data.openid,
                            token: res.data.token,
                        },
                        success: function(res) {
                            if (res.data.code == 1) {
                                that.setData({
                                    databuy: res.data.data,
                                })
                            }

                        }
                    }),
                    // 委托卖
                    wx.request({
                        url: app.url.requestUrl + '/myentrust/sell',
                        method: 'POST',
                        data: {
                            openid: res.data.openid,
                            token: res.data.token,
                            page: 1
                        },
                        success: function(res) {
                            if (res.data.code == 1) {
                                that.setData({
                                    datasell: res.data.data,
                                })
                            }

                        }
                    }),
                    // 委托出价
                    wx.request({
                        url: app.url.requestUrl + '/myentrust/bid',
                        method: 'POST',
                        data: {
                            openid: res.data.openid,
                            token: res.data.token,
                            page: 1
                        },
                        success: function(res) {
                            if (res.data.code == 1) {
                                that.setData({
                                    data: res.data.data,
                                })
                            }
                        }
                    })

            }

        })




    },

    //滑动切换

    swiperTab: function(e) {

        this.setData({

            currentTab: e.detail.current

        });

    },



    //点击切换

    clickTab: function(e) {

        if (this.data.currentTab === e.target.dataset.current) {

            return false;

        } else {

            this.setData({

                currentTab: e.target.dataset.current

            })

        }

    },
    onReady: function() {
        // this.scrollHeight();
    },
})